package com.lwx.chapter7;

import java.util.Random;

public class SparseGraphDemo {
    public static void main(String[] args) {
        int N = 20;
        int M = 100;
        SparseGraph graph = new SparseGraph(N,false);
        Random random = new Random();
        for (int i = 0; i < M; i++) {
            int a = random.nextInt(N);
            int b = random.nextInt(N);
            System.out.println(i+":"+a+","+b);
            graph.addEdge(a,b);
        }


        for (int i = 0; i < N; i++) {
            System.out.print(i + ":");
            SparseGraph.adjIterator adjIterator = graph.new adjIterator(graph,i);
            for (int w = adjIterator.begin(); !adjIterator.end() ; w = adjIterator.next()) {
                System.out.print(w+" ");
            }
            System.out.println();
        }
    }
}
